//
//  MikutapCircleViewController.swift
//  Animations
//
//  Created by 姬友大人 (external - Project) on 2022/8/19.
//  Copyright © 2022 sunny. All rights reserved.
//

import UIKit

class MikutapCircleViewController: UIViewController {
    
    private var gcdTimer: DispatchSourceTimer?
    
    let six = LoadingViewSixSwnStar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height));
    
    deinit {
        printLog("销毁")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        view.addSubview(six)
        
        if gcdTimer == nil {
            gcdTimer = DispatchSource.makeTimerSource(queue: DispatchQueue.main)
            gcdTimer?.schedule(deadline: .now(), repeating: 0.5)
            gcdTimer?.setEventHandler(handler: { [weak self] in
                DispatchQueue.main.async {
                    guard let weakSelf = self else { return }
                    let k = arc4random_uniform(2) % 2;
                    if k == 0 {
                        weakSelf.six.showAnimation()
                    }
                }
            })
            gcdTimer?.resume()
        }
    }
}
